<template>
    <el-container>
      <el-header height="50px" style="overflow-y: hidden">
        <div>
          <div
            @click="logout"
            style="margin-top: 10px; float: right"
            class="grid-content bg-purple"
          >
            退出
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="250px">
          <el-row :gutter="0">
            <el-col :span="18" :offset="4"
              ><div class="grid-content bg-purple">CRM管理系统</div></el-col
            >
          </el-row>
          <el-row :gutter="0">
            <el-col :span="6" :offset="4">
              <div>
                <el-avatar
                  src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png"
                ></el-avatar>
              </div>
            </el-col>
            <el-col :span="10">
              <div class="welcome-content">欢迎您:</div>
              <div class="grid-content bg-purple">{{ user }}</div>
            </el-col>
          </el-row>
          <el-menu
            :default-openeds="openeds"
            :router="true"
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#2A3F54"
            text-color="#fff"
            active-text-color="#ffd04b"
          >
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>菜单导航</span>
              </template>
              <el-menu-item-group>
                <el-submenu index="1-1">
                  <template slot="title"
                    ><i class="el-icon-user"></i>部门员工管理</template
                  >
                  <el-menu-item index="/welcome/dept"
                    ><i class="el-icon-loading"></i>部门信息管理</el-menu-item
                  >
                  <el-menu-item index="/welcome/emp"
                    ><i class="el-icon-user-solid"></i>员工信息管理</el-menu-item
                  >
                </el-submenu>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main> <router-view></router-view></el-main>
      </el-container>
    </el-container>
  </template>
    <script>
  export default {
    data() {
      return {
        openeds: ["1", "1-1"],
        uniqueOpened: false,
        user: "",
      };
    },
    mounted() {
      this.getName();
    },
    methods: {
      getName() {
        var user = sessionStorage.getItem("user");
        //var obj = JSON.parse(obj)
        console.log("user:" + user);
        this.user = user;
      },
      //退出方法
      async logout() {
        const url = "/logout";
        const { data: res } = await this.$ajax.get(url, {
          headers: {
            token: localStorage.getItem("token"),
          },
        });
        window.sessionStorage.clear(); // 清空sessionStorage
        window.localStorage.clear(); // 清空localStorage
        this.$router.push("/login"); // 返回登录页面
      },
    },
  };
  </script>
    <style>
  html,
  body,
  #app {
    height: 100%;
    margin: 0;
    padding: 0;
  }
  
  
  .el-container {
    height: 100%;
  }
  .el-header {
    background-color: #2a3f54;
  }
  
  
  .el-aside {
    display: block;
    position: relative;
    overflow-y: hidden;
    background-color: #2a3f54 !important;
    overflow-x: hidden;
  }
  
  
  .el-row {
    margin-bottom: 20px;
  }
  .el-col {
    border-radius: 4px;
  }
  
  
  .bg-purple {
    background: #2a3f54;
  }
  
  
  .welcome-content {
    border-radius: 4px;
    min-height: 36px;
    color: #717977;
    font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
      "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
    font-size: 14px;
  }
  
  
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
    color: white;
    font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
      "Microsoft YaHei", "微软雅黑", Arial, sans-serif;
    font-size: 20px;
  }
  </style>